package com.anxinr.controller.user;

import com.anxinr.pojo.dto.UserDTO;
import com.anxinr.pojo.entity.User;
import com.anxinr.result.Result;
import com.anxinr.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

/**
 * 用户模块
 *
 * @author anxinr
*/
@CrossOrigin
@Slf4j
@RestController
@RequestMapping("/user")
@Api("用户模块")
public class UserController {
    @Autowired
    private UserService userService ;
    /**
     * 用户登录
     * @author anxinr
     * @return HashMap
     */
    @ApiOperation("用户登录")
    @PostMapping("/login")
    public Result<HashMap<String,Object>> login(@RequestBody UserDTO user){
        return new Result(userService.login(user));
    }

    /**
     * 管理员登录
     * @author anxinr
     * @return HashMap
     */
    @ApiOperation("用户登录")
    @PostMapping("/loginAdmin")
    public Result<HashMap<String,Object>> loginAdmin(@RequestBody UserDTO user){
        return new Result(userService.loginAdmin(user));
    }

    /**
     * 用户注册
     * @author anxinr
     * @return HashMap
     */
    @ApiOperation("用户登录")
    @PostMapping("/register")
    public Result<String> register(@RequestBody UserDTO user){
        /**用户注册*/
        userService.register(user) ;
        return Result.success();
    }
















}
